home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / ubmark / data.c < prev    next >
Text File  |  1996-07-10  |  3KB  |  125 lines

  1. /*********************************************************
  2. *
  3. *    data.c
  4. *    output file:    data
  5. *    programmer:    Michael Day
  6. *    copyright:    Michael Day, 1990; LAN TIMES, 1990
  7. *
  8. *    creates a fake database file using random characters,
  9. *    reads records one at a time from the database file,
  10. *    writes each record to a temp file, closes the temp
  11. *    file.
  12. *    background processes open file, write a string to 
  13. *    file, close file, delete file in an endless loop.
  14. *
  15. *    compile each "c" file to the output file listed in 
  16. *    its header.
  17. *    place all files in the /bin directory
  18. *    execute the benchmark by typing "data" at the prompt    
  19. **********************************************************/
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <sys/types.h>
  24. #include <prot.h>
  25.  
  26. #define  CHARS     1000
  27. #define     TEN_MEG 409600
  28.  
  29. char        records[7], proc[7], size[7], cache[2];
  30.  
  31. main()    {
  32.     
  33.     int     i,x, r;
  34.     time_t    beg_time, end_time;
  35.     int    cum_time;
  36.     long    *tloc;
  37.         
  38.     FILE    *db_file, *temp_file, *source;    
  39.     int    randfill(int r);
  40.  
  41.     printf("LAN TIMES multiprocess database benchmark\n");
  42.     printf("Copyright 1990 Michael Day and LAN TIMES\n");
  43.     printf("Enter the number of records to create\n-->");
  44.     scanf("%s", records);
  45.     printf("Enter the size of each record in K\n-->");
  46.     scanf("%s", size);
  47.     printf("Enter the number of background processes to spawn\n-->");
  48.     scanf("%s", proc);
  49.     printf("Enter <1> to fill disk cache with background copy, <0> otherwise\n-->");
  50.     scanf("%s", cache);    
  51.  
  52. /*****     now create the file and fill it with data     *****/
  53.         
  54.         printf("Creating Database Records . . .\n");
  55.         r = (atoi(size) * 1000);
  56.         randfill(r);
  57.  
  58.     if (atoi(cache) == 1)    {
  59.         source = fopen("source.txt", "a");    
  60.         printf("Creating 10MB file for background copy. . .\n");
  61.         for(i = 0; i < TEN_MEG; i++)
  62.             fputs("LAN TIMES Testing Center", source);
  63.     }
  64.  
  65. /*****     start background processes     *****/
  66.  
  67.  
  68.     if(atoi(cache) == 1)        
  69.         system("/bin/cspawn");
  70.  
  71.     for (i = 0; i < atoi(proc); ++i)
  72.         if(system("/bin/dspawn") == 0)
  73.             printf("%i spawned\n", i +1); 
  74.     
  75.  
  76. /*****     read and write each record to a temp file, delete file    *****/
  77.     
  78.     beg_time = time(&tloc);    
  79.     printf("Reading and Writing each record . . .\n");
  80.     db_file = fopen("db", "ab+");
  81.     printf("dbfile opened\n");
  82.     for(i = 0; i < atoi(records); i++)    {
  83.         temp_file = tmpfile(); 
  84.         fread( temp_file, *size, 1, db_file);
  85.         fclose(temp_file);
  86.     }
  87.  
  88. /*****     clean up *****/
  89.  
  90. /*    fclose(db_file);  */
  91.     end_time = time(&tloc);
  92.     cum_time = (end_time - beg_time);
  93.     printf("Elapsed time: %i seconds\n", cum_time);
  94.     printf("Parameters: %s records of %sK each\n", records, size);
  95.     printf("            %s background processes\n", proc); 
  96.     exit(0);
  97. }
  98.  
  99.  
  100.  
  101.  
  102. /*************************************************************************
  103. *    randfill()
  104. *************************************************************************/
  105.  
  106. int randfill(int r)    {
  107.     
  108.     int     x, y;
  109.     
  110.     FILE     *db_file;        
  111.     
  112.     db_file = fopen("db", "wb+");
  113.     srand48(x);        
  114.     for (x = 0; x < (r * atoi(records)); x++)    {
  115.         y = (int)lrand48();
  116.         putc((y/10000000), db_file);
  117.     }
  118.     fclose(db_file);
  119.     return(0);
  120. }
  121.  
  122.  
  123.  
  124.     
  125.